package manage;

import logIn.MysqlConnectionTool;

import javax.swing.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * @Author Jian Chen long
 * @Date 2021/6/18 21:27
 */
public class selectLeft extends JFrame {
    private JTextArea selectLeft = new JTextArea();
    private JScrollPane pane = new JScrollPane();

    public selectLeft(){
        pane.setViewportView(selectLeft);
        selectLeft.setEditable(false);
        this.add(pane);

        this.setTitle("库存信息");
        selectLeft.setText("编号\t" + "型号\t" + "品牌\t" + "价格\t" + "数量\n");
        this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        this.setSize(480,280);
        this.setLocationRelativeTo(null);
        this.setResizable(false);

        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try{
            conn = MysqlConnectionTool.getConnection();
            // 获取数据库操作对象
            String sql = "select * from goods";
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            while (rs.next()){
                selectLeft.append(rs.getString("编号") + "\t"
                        + rs.getString("商品") + "\t"
                        + rs.getString("品牌") + "\t"
                        + rs.getString("价格") + "\t"
                        + rs.getString("数量") + "\n");
            }
        }catch (Exception E){
            JOptionPane.showMessageDialog(null,"查询失败,请重试");
            return;
        }finally {
            MysqlConnectionTool.close(conn,ps,rs);
        }
    }
}
